package edu.whut.service.impl;

import edu.whut.dao.CreationDao;
import edu.whut.entity.Approval;
import edu.whut.entity.Comment;
import edu.whut.entity.Creation;
import edu.whut.service.CreationService;
import edu.whut.utils.IdWorker;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;

@Service
public class CreationServiceImpl implements CreationService {

    @Resource
    CreationDao creationDao;


    @Override
    public Boolean addCreation(Creation creation) {
        creation.setCreationId(IdWorker.nextId());
        creation.setTime(new Date());
        return creationDao.insert(creation)>0;
    }

    @Override
    public Boolean deleteCreation(Long creationId) {
        return creationDao.deleteById(creationId)>0;
    }

    @Override
    public Boolean updateCreation(Creation creation) {
        return creationDao.updateById(creation)>0;
    }

    @Override
    public Creation getCreation(Long creationId) {
        return creationDao.selectById(creationId);
    }

    @Override
    public List<Creation> getCreationByUsername(String username) {
        HashMap<String,Object> map=new HashMap<>();
        map.put("username",username);
        return creationDao.selectByMap(map);
    }

    @Override
    public List<Creation> getAllCreation() {
        HashMap<String,Object> map=new HashMap<>();
        return creationDao.selectByMap(map);
    }

    @Override
    public List<Creation> getCreationByPoemId(Long poemId){
        HashMap<String,Object> map=new HashMap<>();
        map.put("poemId",poemId);
        return creationDao.selectByMap(map);
    }

}
